/* 创建同户集合 */
// 引入mongoose第三方模块
const mongoose = require('mongoose');
const moment = require('moment')

// 创建用户集合规则
const userSchema = mongoose.Schema({
  username: {
    type: String,
    required: true,
    minlength: 2,
    maxlength: 10
  },
  password: {
    type: String,
    required: true
  },
  // admin 超级管理员    normal 普通管理员
  roleType: {
    type: Number,
	default: 3
  },
  // 0是禁用状态，1是启用状态 
  state: {
    type: Number,
    default: 1
  },
  email: {
	type: String,
	required: false
  },
  avatar: {
	  type: String,
	  default: '/upload/default-avatar.png'
  },
  nickname: {
	  type: String,
	  default: moment().format('YYYY-MM-DD HH:mm:ss') + '用户'
  }
});

// 创建集合
const User = mongoose.model('User', userSchema);

// 将用户集合作为模块成员进行导出
module.exports = {
  User
}